<template>
	<view class="content">
		 <!-- 标题部分 -->
		<view class="login_from_input">
			<view class="form-left">认证类型</view>
			<view class="login_from_fun">
				<view style="width: 100%;">
					<radio-group style="font-size: 25rpx;float: left;" @change="((e) =>change(e))">
					  <radio value="2" checked/>
					  企业
					  <radio value="3"  />
					  服务机构
					</radio-group>
				</view>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">企业名称</view>
			<view class="login_from_fun"><input type="text" v-model="formData.realName" placeholder="请输入企业名称" ></view>
		</view>
<!-- 		<view class="login_from_input">
			<view class="form-left">企业类型</view>
			<view class="login_from_fun"><input type="text" v-model="formData.companyType" placeholder="点击选择企业类型" ></view>
		</view> -->
		<view class="login_from_input">
			<view class="form-left">企业性质</view>
			<view class="login_from_fun">
				<picker style="width: 100%;" @change="typeChange" :value="typeIndex"  :range-key="'dictLabel'" :range="typeArray">
					<view style="font-size: 25rpx; float:left;" class="uni-input">{{typeArray[typeIndex].dictLabel || '请选择企业性质'}}</view>
				</picker>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">统一编号</view>
			<view class="login_from_fun"><input type="number" v-model="formData.organCode" placeholder="请输入统一编号"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">企业法人</view>
			<view class="login_from_fun"><input  v-model="formData.legalPerson" placeholder="请输入法人姓名"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">法人身份证号</view>
			<view class="login_from_fun"><input  v-model="formData.idNo" placeholder="请输入法人身份证号"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">法人联系方式</view>
			<view class="login_from_fun"><input type="number" v-model="formData.contact"  maxlength="11" placeholder="请输入联系方式"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">企业简介</view>
			<view class="login_from_fun" style="text-align: left;">
				<textarea v-model="formData.information" placeholder="请输入企业简介"></textarea>
			</view>
		</view>
		<!-- 上传各类图片 -->
		<view class="ID-mian">
			<text style="font-weight: 700;">身份证正面(上传)</text>
			<view class="card-zheng">
				<view class="zheng_left" v-show="isShow">
					<image src="http://113.142.144.25:9301/statics/appimg/zheng_new.png" mode="" @tap='touchphoto1'></image>
				</view>
				<view class="zheng_right" v-show="!isShow">
					<image :src="formData.cardFront" @tap='touchphoto1'></image>
				</view>
			</view>
			<text style="font-weight: 700;">身份证反面(上传)</text>
			<view class="card-fan">
				<view class="fan_left" v-show="isShow1">
					<image src="http://113.142.144.25:9301/statics/appimg/fan_new.png" mode="" @tap='touchphoto2'></image>
				</view>
				<view class="fan_right" v-show="!isShow1">
					<image :src="formData.cardBank" @tap='touchphoto2'></image>
				</view>
			</view>
			<text style="font-weight: 700;">营业执照(上传)</text>
			<view class="card-fan">
				<view class="fan_left" v-show="isShow2">
					<image src="http://113.142.144.25:9301/statics/appimg/upload_pic_new.png" mode="" @tap='touchphoto3'></image>
				</view>
				<view class="fan_right" v-show="!isShow2">
					<image :src="formdata.yyzzImg" @tap='touchphoto3'></image>
				</view>
			</view>
		</view>
		<view class="devideline"></view>
		<!-- 提交按钮 -->
		<view class="uni-form-item uni-column">
			<view>
				<button type="primary" @click="submitNeeds()">提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	import * as uploadUtil from '@/utils/photoUploadUtil.js'
	import * as mydata from '@/api/system/dict/data.js'
	import * as renzheng from '@/api/personCenter/index.js'
	import env from "@/utils/env.js"
	
	export default {
		components:{

		},
			data() {
				return {
					show: false,
					formData: {
						id: null,
						memberId: null,
						userType: '2',
						realName: null,//企业名称
						idNo: null,
						natrue: null,//企业性质
						legalPerson: null,//法人
						contact: null,//联系方式
						cardFront: null,//身份证正面
						cardBank: null,//身份证反面
						address: null,
						organCode: null,
						yyzzImg: null,
						information: null,
						delFlag: null,
						createBy: null,
						createTime: null,
						updateBy: null,
						updateTime: null,
						remark: null,
					},
					srcs: [],
					execId: 0,
					taskId: '',
					hasDescription: false,
					companyTypeList:[],
					fieldList:[],
					commandTypeList:[
						{id:'0',name:''}
					],
					imageStyles:{
						width:64,
						height:64,
						border:{
							color:"#888888",
							width:2,
							style:'dashed',
							radius:'2px'
						}
					},
					//企业性质类型
					typeArray: [
					],
					//企业性质类型选中项
					typeIndex: 0,
					canlendarShow:false,
					typeList:[
						
					],
					keyName:'keyName',
					//身份证上传相关变量：
					V_TPID: '',
					V_TPID1: '',
					yyzz:'',
					curl: '',
					isShow:true,
					isShow1:true,
					isShow2:true,
					query:{
						pageNum:'0',
						pageSize:'10',
						userId:''
					},
					isRenZheng:false
				}
			},
			onLoad(){
				this.getUser()
				this.getTypeList()
				this.getMyCertification()
			},
			methods:{
				change(e) {
					this.formData.userType = e.detail.value
				},
				getUser(){
					var value = uni.getStorageSync('userInfo')
					this.query.userId = value.login_user.member.id
					this.formData.memberId = value.login_user.member.id
				},
				getMyCertification(){
					renzheng.getMemberEnterInfo(this.query.userId).then((res)=>{
						if(res.code == 200 && res.data){
							this.formData = res.data 
							this.show = false
							this.isShow1 = false
							this.isShow2 = false
							this.isRenZheng = true
						}else{
							uni.showToast({
								icon:'none',
								title:'暂无认证信息，请先提交！'
							})
							this.isRenZheng = false
						}
					})
				},
				submitNeeds(){
					//认证提交
					if(!this.isRenZheng){
						renzheng.addMemberEnter(this.formData).then((res)=>{
							uni.showModal({
								content:'提交成功！'
							})
							uni.navigateBack()
						})
					}else{
						renzheng.updateMemberEnter(this.formData).then((res)=>{
							uni.showModal({
								content:'提交成功！'
							})
							uni.navigateBack()
						})
					}
				},
				changeDate(e){
					this.canlendarShow = false;
					var year =  e.year 
					var month = e.month
					if(month < 10){
						month = "0" + month
					}
					var day = e.day
					if(day < 10){
						day = "0" + month
					}
					
					this.formData.deadline = year + '-' + month + '-' + day
				},
				getTypeList(){
					mydata.getDicts("u_enter_nature").then((response) => {
					  this.typeArray = response.data;
					});
				},
				typeChange(e){
					this.typeIndex = e.detail.value;
					this.formData.type = this.typeIndex;
				},
				//上传身份证
				touchphoto1() {
					let that = this
					uni.chooseImage({
						count: 1,
						success: (res) => {
							// 2上传文件
							uni.uploadFile({
								url: env.baseUrl+"/file/upload",
								filePath: res.tempFilePaths[0],
								name: "file",
								success: (res2) => {
									var data = JSON.parse(res2.data)
									// console.log(data)
									if (data.code == 200) {
										that.formData.cardFront = data.data.url
										that.isShow = false
									} else {
										uni.showModal({
											title: "提示信息",
											content: "上传失败！"
										})
										that.isShow = true
									}
								}
							})
						}
					})
			},
			touchphoto2() {
				let that = this
				uni.chooseImage({
					count: 1,
					success: (res) => {
						// 2上传文件
						uni.uploadFile({
							url: env.baseUrl+"/file/upload",
							filePath: res.tempFilePaths[0],
							name: "file",
							success: (res2) => {
								var data = JSON.parse(res2.data)
								if (data.code == 200) {
									that.formData.cardBank = data.data.url
									that.isShow1 = false
								} else {
									uni.showModal({
										title: "提示信息",
										content: "上传失败！"
									})
									that.isShow1 = true
								}
							}
						})
					}
				})
			},
			touchphoto3() {
				let that = this
				uni.chooseImage({
					count: 1,
					success: (res) => {
						// 2上传文件
						uni.uploadFile({
							url: env.baseUrl+"/file/upload",
							filePath: res.tempFilePaths[0],
							name: "file",
							success: (res2) => {
								var data = JSON.parse(res2.data)
								if (data.code == 200) {
									that.formData.yyzzImg = data.data.url
									console.log(that.formData.yyzzImg)
									that.isShow2 = false
								} else {
									uni.showModal({
										title: "提示信息",
										content: "上传失败！"
									})
									that.isShow2 = true
								}
							}
						})
					}
				})
			},
			  //返回上一页
			back(){
				if(this.isShow==false && this.isShow1==false){
					uni.navigateBack()
				}else{
					uni.showToast({
						icon: 'none',
						title: "身份证信息未完善",
						duration: 4000
					});
					util.hideLoading();
				}
			}
		}
	}
</script>

<style>
	.content{
		height: 500rpx;
		background-color: #e5e5e5;
	}
	
	.uni-form-item {
		margin: 60rpx 30rpx;
		border-radius: 50px;
		}
		
	.uni-form-item button{
		background-color: #016fb8;
		height: 70rpx;
		font-size: 28rpx;
		margin-top: 80rpx;
	}
	
	.login_from_input{
		width: 100%; 
		height:auto; 
		display: flex; 
		flex-direction: row; 
		justify-content: space-between; 
		align-items: center; 
		border-bottom: 1px #eee solid; 
		padding: 20upx 0px; 
		margin: 0px auto; 
		background-color: #fff;
	} 
	
	.login_from_name{
		width: 30%; 
		margin-left: 40rpx;
		font-size: 30rpx;
	}
	.login_from_fun{ 
		width: 70%; 
		display: flex; 
		flex-direction: row; 
		justify-content: flex-end; 
		text-align: right;  
	}
	
	.login_from_fun input{ 
		width: 100%; 
		text-align: left; 
		font-size: 14px;  
	}
	
	.form-left{
		margin-left: 16px;
		padding:5rpx 0;
	}
	
	.form-right{
		margin-top: 6px;
		margin-left: 6px;
		padding:5px 0;
		width: 90%;
		border: 1px solid #D8D8D8;
		border-radius: 3px;
	}

	.upLoadImg{
		width: 96rpx;
		height: 96rpx;
		background-color: #FFFFFF;
		margin-top: 16rpx;
		margin-left: 6px;
	}
	
	.devideline {
		float: left; 
		height: 0.3rpx;
		width:100%;
		background-color: #eeeeee;
		margin-top: 25rpx;
		margin-bottom: 15rpx;
	}
	
	textarea {
	        margin-right: 20rpx;
	        height: 300rpx;
	        word-wrap : break-word;
			text-align: left;
			font-size: 15px;
			
	}
	
	/* 身份证上传样式 */
	.ID-mian {
			background-color: white;
			margin-top: 25rpx;
			margin-left: 25rpx;
		}
	
		.card-zheng {
			width: 100%;
			height: 240px;
			display: flex;
			justify-content: space-around;
		}
	
		.zheng_left {
			width: 70%;
			height: 100%;
			display: inline-block;
		}
	
		.zheng_left image {
			width: 90%;
			height: 70%;
			line-height: 70%;
			margin-top: 30px;
			margin-left: 10px;
		}
	
		.zheng_right {
			width: 70%;
			height: 100%;
			display: inline-block;
		}
	
		.zheng_right image {
			width: 90%;
			height: 60%;
			line-height: 70%;
			margin-top: 30px;
			margin-left: 10px;
		}
	
		.card-fan {
			width: 100%;
			height: 240px;
			display: flex;
			justify-content: space-around;
		}
	
		.fan_left {
			width: 70%;
			height: 100%;
			display: inline-block;
		}
	
		.fan_left image {
			width: 90%;
			height: 70%;
			line-height: 70%;
			margin-top: 30px;
			margin-left: 10px;
		}
	
		.fan_right {
			width: 70%;
			height: 100%;
			display: inline-block;
		}
	
		.fan_right image {
			width: 90%;
			height: 70%;
			line-height: 70%;
			margin-top: 30px;
			margin-left: 10px;
		}
	
</style>